package com.Sell.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.Sell.manage.domain.MachineGoods;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Sell.common.annotation.Log;
import com.Sell.common.core.controller.BaseController;
import com.Sell.common.core.domain.AjaxResult;
import com.Sell.common.enums.BusinessType;
import com.Sell.manage.domain.Machine;
import com.Sell.manage.service.IMachineService;
import com.Sell.common.utils.poi.ExcelUtil;
import com.Sell.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author emmm
 * @date 2024-12-15
 */
@RestController
@RequestMapping("/manage/machine")
public class MachineController extends BaseController
{
    @Autowired
    private IMachineService machineService;

    /**
     * 查询设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:list')")
    @GetMapping("/list")
    public TableDataInfo list(Machine machine)
    {
        startPage();
        List<Machine> list = machineService.selectMachineList(machine);
        return getDataTable(list);
    }

    /**
     * 导出设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:export')")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Machine machine)
    {
        List<Machine> list = machineService.selectMachineList(machine);
        ExcelUtil<Machine> util = new ExcelUtil<Machine>(Machine.class);
        util.exportExcel(response, list, "设备管理数据");
    }

    /**
     * 获取设备管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(machineService.selectMachineById(id));
    }

    /**
     * 新增设备管理
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:add')")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Machine machine)
    {
        return toAjax(machineService.insertMachine(machine));
    }

    /**
     * 修改设备管理
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:edit')")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Machine machine)
    {
        return toAjax(machineService.updateMachine(machine));
    }

    /**
     * 删除设备管理
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:remove')")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(machineService.deleteMachineByIds(ids));
    }

    /**
     * 获取设备关联的商品信息
     */
    @PreAuthorize("@ss.hasPermi('manage:machine:query')")
    @GetMapping("/goods/{machineId}")
    public AjaxResult getMachineGoods(@PathVariable Long machineId) {
        List<MachineGoods> machineGoodsList = machineService.selectMachineGoodsByMachineId(machineId);
        return AjaxResult.success(machineGoodsList);
    }


}
